package cn.bitkit.component.aop;

import cn.bitkit.base.annotation.Lock;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.util.StopWatch;

@Slf4j
@Aspect
public class PerfHandler {

    @Around(value = "@annotation(lockTag)")
    public Object doLock(ProceedingJoinPoint joinPoint, Lock lock) throws Throwable{
        StopWatch watch = new StopWatch();
        watch.start();
        Object res = joinPoint.proceed();
        watch.stop();
        log.info("[{}]耗时:{}", joinPoint.getSignature().getName(), watch.getTotalTimeMillis());
        return res;
    }

}
